<template>
    <div>
              <!-- Breadcrumb 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/scheduling' }">新增排班规则</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/rule' }">生成排班计划 </el-breadcrumb-item>
      <!-- <el-breadcrumb-item>常数列表</el-breadcrumb-item> -->
    </el-breadcrumb>
<!-- 卡片 -->
    <el-card>
         <el-row type="flex" class="text" justify="center">
              <el-col :span="4" >新增排班规则</el-col>
          </el-row>
 <!-- 科室选择下拉列表框 -->
 <form :inline="true"><el-row type="flex" justify="center" :gutter="20">
      <el-col :span="10">科室选择
         <el-select size="mini" v-model="value" placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
      </el-col>
       <el-col :span="2">
        <el-button type="primary" size="mini"  @click="getDataList">查询</el-button
        >
      </el-col>
      <el-col :span="2">
        <el-button type="primary" size="mini" >清空</el-button> 
      </el-col></el-row>
 </form>

   <el-table class="table"    :data="datalist"  stripe>
        <!-- 首列添加插槽 获取当前行id -->
        <el-table-column  prop="id" width="65">
             <template slot-scope="select">
                   <el-checkbox @change="checked=>checkboxSelect(checked,select.row.id)"></el-checkbox>
             </template>
        </el-table-column>
        <el-table-column prop="rule.rulename" label="规则名称"> </el-table-column>
        <el-table-column prop="department.deptname" label="科室名称"> </el-table-column>
         <el-table-column prop="user.realname" label="医生名字"> </el-table-column>
          <el-table-column prop="rule.week" label="时间"> </el-table-column>
      </el-table>

      <el-form inline>
        <el-form-item label="开始日期" label-width="70px">
          <el-date-picker size="mini" v-model="queryInfo.startTime" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="结束日期" label-width="70px">
          <el-date-picker size="mini" v-model="queryInfo.endTime" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <el-button type="primary" @click="getDataList">查询</el-button>
        <el-button type="primary" @click="addScheduing">选取规则生成排班计划</el-button>
      </el-form>
    </el-card>
    </div>
</template>

<script>
export default {
    data(){
        return{
             queryInfo: {
        startTime: "",
        endTime: "",
        pageNum: 1,
        pageSize: 5
      },
      datalist: [],
      departmentList: [],
      total: 0
        };
    },
     created() {
    this.getDataList();
  },
  methods:{
      //查询Rule
         async getDataList() {
      const { data: res } = await this.$http.post(
        "scheduling/findSchedulingByPage",
        this.queryInfo
      );
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg);
      }
      this.datalist = res.Schedulings;
      this.total = res.totalpage;
      console.log(res);
    },

    //生成排班计划
     //生成排班计划
    async addScheduing(){
      const confirmResult = await this.$confirm(
        "生成新的计划将会覆盖旧的计划，是否生成？",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).catch(err => err);
      // 如果用户确认删除，则返回值为字符串 confirm
      // 如果用户取消了删除，则返回值为字符串 cancel
      // console.log(confirmResult)
      if (confirmResult !== "confirm") {
        return this.$message.info("已取消生成");
      }
        const { data: res } = await this.$http.get(
      "scheduling/addScheduling"
      )
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg);
      }
      this.$message.success(res.meta.msg);
      let date=new Date();
      date.setDate(1)
      this.queryInfo.startTime = moment(date).format("YYYY-MM-DD");
      date.setMonth(date.getMonth()+1)
      date.setDate(0)
      this.queryInfo.endTime = moment(date).format("YYYY-MM-DD");
      this.getDataList();
      }
  }
}
</script>

<style lang="less" scoped>

.text{
    margin-bottom: 40px;
}

.table{
    padding-bottom: 35px;
}

.rule{
  padding-top: 20px;
  margin-top: 0%;
  margin-left: 150px;
  text-align:"center"
}
</style>